package org.whuims.core.dataprocessor.page;

import org.ansj.domain.Result;
import org.ansj.library.DATDictionary;
import org.ansj.library.UserDefineLibrary;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Created by cheng on 2016/12/29.
 */
public class WordSplitter {
    private static WordSplitter instance = new WordSplitter();

    public WordSplitter() {
        init();
    }

    public static WordSplitter getInstance() {
        return instance;
    }

    private void init() {
        try {
            List<String> lines = FileUtils.readLines(new File("src/main/webapp/resource/userLibrary.txt"));
            for (String line : lines) {
                line = line.trim();
                if (!DATDictionary.isInSystemDic(line)) {
                    UserDefineLibrary.insertWord(line.trim(), "nw", 5000);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Result parse(String text) {
        return NlpAnalysis.parse(text);
    }
}
